---
import { attrs, html, transform } from "ultrahtml";
import sanitize from "ultrahtml/transformers/sanitize";
import swap from "ultrahtml/transformers/swap";
import { compiledContent, getHeadings } from '../../../../README.md';
import MainLayout from '../layouts/MainLayout.astro';
import * as CONFIG from '../config';

// Clean content of <h1> because already created by the layout
// Clean <div> to remove the ‹div›RIOTS banner
const content = compiledContent();
const output = await transform(content, [
  swap({
    a: (props, children) => {
      const newProps = {...props};
      const href = props.href;
      if (!href.startsWith('https://jampack.divriots.com')) {
        newProps.rel = "nofollow";
      }
      return html`<a ${attrs(newProps)}>${children}</a>`
    },
  }),
  sanitize({ dropElements: ["h1", "div"] }),
]);
---

<MainLayout frontmatter={{ title: 'Jampack', description: undefined, layout: undefined}} headings={getHeadings()}>
   <div set:html={output}/>
</MainLayout>